package tt.dz.order.vo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import tt.dz.order.exception.ParamLackException;
import tt.dz.order.exception.ParamNotFoundInSystemException;
import tt.dz.order.pojo.OrderServiceInfo;

/**
 * 
 * 
 * @name 订单项定义
 * @author Anson
 * @version 1.0
 * @summary
 * @desc
 *
 */
public class AdvanceOrderItem extends BaseVo {
	// (必须) 服务编号
	private String serviceNo;
	// (必须) 资源（桩）所属运营商编号
	private String serviceProviderCode;
	// (必须) 电站Id-->门店id
	private String plantId;
	// (必须) 桩的编号-->网点id
	private String equipmentNo;
	// (必须) 辅助设备编号,枪的编号-->车辆vin号
	private String auxEquipmentNo;
	// (非必须) 单价，oms系统保存的原始单价
	private BigDecimal unitPrice;
	// (必须) 总价，如电费
	private BigDecimal totalPrice;
	// (必须) 购买数量，如预约时间、电量等
	private BigDecimal buyNum;
	// (必须) 服务开始时间
	private Date startTime;
	// (必须) 服务结束时间
	private Date endTime;
	// 白名单用户使用合作建设资源的打折信息
	private WhiteListInfo whiteListInfo;
	// 分润规则信息
	private DivideInfo divideInfo;
	// 该运营商提供的服务是否是成本类的服务，0：否 1：是
	private transient int isCost;
	// 计量单位编号
	private transient int unitNo;
	// 订单项描述
	private String message;

	/**
	 * 属性拷贝，缺少上层相关信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public OrderBaseData convertOrderBaseData() {
		OrderBaseData data = new OrderBaseData();
		// 服务编号
		data.setServiceNo(this.getServiceNo());
		// 资源（桩）所属运营商编号
		data.setServiceProviderCode(this.getServiceProviderCode());
		// 该运营商提供的服务是否是成本类的服务，0：否 1：是
		data.setIsCost(this.getIsCost());
		// 计量单位编号
		data.setUnitNo(this.getUnitNo());
		// 电站Id
		data.setPlantId(this.getPlantId());
		// 桩的编号
		data.setEquipmentNo(this.getEquipmentNo());
		// 辅助设备编号,枪的编号
		data.setAuxEquipmentNo(this.getAuxEquipmentNo());
		// 单价，oms系统保存的原始单价
		data.setUnitPrice(this.getUnitPrice());
		// 总价，如电费
		data.setTotalPrice(this.getTotalPrice());
		// 购买数量，如预约时间、电量等
		data.setBuyNum(this.getBuyNum());
		// 服务开始时间
		data.setStartTime(this.getStartTime());
		// 服务结束时间
		data.setEndTime(this.getEndTime());
		// 白名单用户使用合作建设资源的打折信息
		data.setWhiteListInfo(this.getWhiteListInfo());
		// 分润规则信息
		data.setDivideInfo(this.getDivideInfo());
		// 订单项描述
		data.setMessage(this.getMessage());
		return data;
	}

	/**
	 * 订单项校验
	 * 
	 * @throws ParamLackException
	 * @throws ParamNotFoundInSystemException
	 */
	public void validate() throws ParamLackException, ParamNotFoundInSystemException {
		// 查询所有服务的服务号和服务名称
		Map<String, String> orderOrderServiceInfoMap = OrderServiceInfo.getAllServiceCodeAndName();
		if (StringUtils.isBlank(serviceNo)) {
			throw new ParamLackException("serviceNo为空");
		}
		if (!orderOrderServiceInfoMap.containsKey(serviceNo)) {
			throw new ParamNotFoundInSystemException("serviceNo为空");
		}
		if (StringUtils.isBlank(serviceProviderCode)) {
			throw new ParamLackException("serviceProviderCode为空");
		}
		if (StringUtils.isBlank(plantId)) {
			throw new ParamLackException("plantId为空");
		}
		if (StringUtils.isBlank(equipmentNo)) {
			throw new ParamLackException("equipmentNo为空");
		}
		if (StringUtils.isBlank(auxEquipmentNo)) {
			throw new ParamLackException("auxEquipmentNo为空");
		}
		if (unitPrice == null && totalPrice == null) {
			throw new ParamLackException("unitPrice和totalPrice为空");
		}
		if (buyNum == null) {
			throw new ParamLackException("buyNum为空");
		}
		if (startTime == null) {
			throw new ParamLackException("startTime为空");
		}
		if (endTime == null) {
			throw new ParamLackException("endTime为空");
		}
		if (whiteListInfo != null) {
			whiteListInfo.validate();
		}
		if (divideInfo != null) {
			divideInfo.validate();
		}
	}

	public AdvanceOrderItem() {
		super();
	}

	public String getServiceNo() {
		return serviceNo;
	}

	public void setServiceNo(String serviceNo) {
		this.serviceNo = serviceNo;
	}

	public String getServiceProviderCode() {
		return serviceProviderCode;
	}

	public void setServiceProviderCode(String serviceProviderCode) {
		this.serviceProviderCode = serviceProviderCode;
	}

	public int getIsCost() {
		return isCost;
	}

	public void setIsCost(int isCost) {
		this.isCost = isCost;
	}

	public int getUnitNo() {
		return unitNo;
	}

	public void setUnitNo(int unitNo) {
		this.unitNo = unitNo;
	}

	public String getPlantId() {
		return plantId;
	}

	public void setPlantId(String plantId) {
		this.plantId = plantId;
	}

	public String getEquipmentNo() {
		return equipmentNo;
	}

	public void setEquipmentNo(String equipmentNo) {
		this.equipmentNo = equipmentNo;
	}

	public String getAuxEquipmentNo() {
		return auxEquipmentNo;
	}

	public void setAuxEquipmentNo(String auxEquipmentNo) {
		this.auxEquipmentNo = auxEquipmentNo;
	}

	public BigDecimal getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(BigDecimal unitPrice) {
		this.unitPrice = unitPrice;
	}

	public BigDecimal getTotalPrice() {
		return totalPrice;
	}

	public void setTotalPrice(BigDecimal totalPrice) {
		this.totalPrice = totalPrice;
	}

	public BigDecimal getBuyNum() {
		return buyNum;
	}

	public void setBuyNum(BigDecimal buyNum) {
		this.buyNum = buyNum;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public WhiteListInfo getWhiteListInfo() {
		return whiteListInfo;
	}

	public void setWhiteListInfo(WhiteListInfo whiteListInfo) {
		this.whiteListInfo = whiteListInfo;
	}

	public DivideInfo getDivideInfo() {
		return divideInfo;
	}

	public void setDivideInfo(DivideInfo divideInfo) {
		this.divideInfo = divideInfo;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

}
